GBML manual / Drawing

Palettes - recoloring a picture

A picture remembers color numbers and a palette says which color each number is, so one picture can be drawn in many sets of colors - for one instance, one background, the room's tiles, text, particles or the zoomable background.

Paint by numbers

A picture on the Game Boy Advance does not store colors. It stores numbers. Each pixel says "I am color number 3", and a separate list says what color number 3 is. That list is a palette. A 16-color palette is a list of 16 colors; the picture just points into it.

That is the trick behind every "same enemy, different color" in a game. You draw the enemy once. You make a second palette with the same 16 places filled with different colors. Draw the enemy with the second palette and it looks new, and the picture only takes up room once.

Palettes are things you make in the Paint tab and give a name, like a sprite or a font. A game only carries the palettes it actually uses.

A palette withfits
16 colorssprites, backgrounds, a room's tiles, text and particles
256 colorsthe zoomable background, which is drawn with 256

Color number 0 is the see-through one in a 16-color picture, so the first color of a palette is not drawn on a sprite.

Swapping while the game runs

There is one call for each kind of picture. All six take a palette, and all six take nothing to mean "go back to the picture's own colors".

CallRecolors
sprite_paletteonly the instance that calls it
background_palettea background you made with background_create
tile_layer_palettethe floor and walls of the room you are in
text_palettethe letters draw_text draws
effect_palettethe particles of an effect
zoom_background_palettethe room's zoomable background
// Create event of one enemy out of a crowd
sprite_palette(pal_doc_gold);

Only this enemy turns gold. Every other copy of the same object keeps its colors, because the palette belongs to the instance that asked for it.

Setting a palette without writing code

You can also pick a palette in the editor: the room's Set palette list (Room Editor, Tile Palette, Tilesets), an object's default palette (every new copy starts with it), and a placed copy's own palette. They do the same thing as the calls above. Code that runs later still wins: if your code says sprite_palette(nothing), the copy goes back to its sprite's own colors.

The 16 palette slots

The console can show 16 different palettes for sprites at once, and another 16 for backgrounds. That sounds like plenty, but sprites that look alike share a slot, and sprites that look different do not:

If a seventeenth palette asks for a slot, the game cannot give it one. A development build stops because the console ran out of sprite palettes. A release build keeps going and leaves that picture in its own colors. Use the same palette for more of your things, or show fewer different ones at once.

The Budgets panel counts the palettes a room can show at once. A background picture or a tileset can also be drawn with several palettes side by side, each taking a slot of the same 16 - see One picture, several palettes.

Things worth knowing

See also: Drawing and the draw orderOne picture, several palettessprite_palettebackground_palettetile_layer_palettetext_paletteeffect_palettezoom_background_paletteBudgets